<html>
<head><meta charset="utf-8"><title>Volatile · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile.html">Volatile</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="169076077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile/near/169076077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile.html#169076077">(Jun 26 2019 at 20:16)</a>:</h4>
<p><a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/152" target="_blank" title="https://github.com/rust-lang/unsafe-code-guidelines/issues/152">https://github.com/rust-lang/unsafe-code-guidelines/issues/152</a> makes me so sad :(</p>



<a name="169076097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile/near/169076097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile.html#169076097">(Jun 26 2019 at 20:17)</a>:</h4>
<p>The OP was all about the interaction with concurrency, and now everyone drowns that in a discussion about volatile load/store tearing that is only relevant for MMIO</p>



<a name="169079065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile/near/169079065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile.html#169079065">(Jun 26 2019 at 20:55)</a>:</h4>
<p>How is tearing only relevant for MMIO ? If you have two threads reading/writing from/to shared memory using volatile, those can tear</p>



<a name="169079163"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile/near/169079163" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile.html#169079163">(Jun 26 2019 at 20:56)</a>:</h4>
<p>so tearing quite intrinsic to volatile</p>



<a name="169079204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile/near/169079204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile.html#169079204">(Jun 26 2019 at 20:57)</a>:</h4>
<p>that thread is about being able to do  reads that returns arbitrary but initialized data in case of a race</p>



<a name="169079212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile/near/169079212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile.html#169079212">(Jun 26 2019 at 20:57)</a>:</h4>
<p>one of the main reasons data-races are UB in C is because of tearing</p>



<a name="169079213"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile/near/169079213" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile.html#169079213">(Jun 26 2019 at 20:57)</a>:</h4>
<p>whether tearing happens or not is irrelevant</p>



<a name="169079226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile/near/169079226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile.html#169079226">(Jun 26 2019 at 20:57)</a>:</h4>
<p>no</p>



<a name="169079238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile/near/169079238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile.html#169079238">(Jun 26 2019 at 20:57)</a>:</h4>
<p>the main reason data races are UB in C is because C compilers like to duplicate reads</p>



<a name="169079250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile/near/169079250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile.html#169079250">(Jun 26 2019 at 20:57)</a>:</h4>
<p>which is <em>much worse</em> than tearing</p>



<a name="169080430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile/near/169080430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile.html#169080430">(Jun 26 2019 at 21:10)</a>:</h4>
<p>i wouldn't say they are much worse - they are differently worse</p>



<a name="169080613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile/near/169080613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile.html#169080613">(Jun 26 2019 at 21:13)</a>:</h4>
<p>no it's strictly worse. every effect you might have with tearing, you also have with duplicate reads, and more.</p>



<a name="169081280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile/near/169081280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile.html#169081280">(Jun 26 2019 at 21:21)</a>:</h4>
<p>and in particular, when the guarantee in case of a data-race is "give me any data", then tearing just is not a problem</p>



<a name="169081299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile/near/169081299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile.html#169081299">(Jun 26 2019 at 21:21)</a>:</h4>
<p>even doing byte-wise reads would be fine, as long as every byte is only read once</p>



<a name="169081314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile/near/169081314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Volatile.html#169081314">(Jun 26 2019 at 21:21)</a>:</h4>
<p>this is what makes the entire tearing discussion off-topic for the original question</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>